<?php
/**
 * Controller to manage users' groups in admin area
 * 
 * @author Konstantin Shamko <konstantin.shamko@gmail.com> 
 * @version 0.0.1
 * @copyright  Copyright (c) 2009 Konstantin Shamko
 * @category VaselinEngine
 * @package Usermanagement Module
 * @subpackage Controller 
 * @license  New BSD License
 * 
 */
class admin_GroupsController extends Bel_Controller_Aed {	
	
	/**
	 * Initialization
	 *
	 */
	function init() {
		$this->_model = new Models_Usermanagement_Groups ( );
		$this->_formname = 'user_groups_form';
		parent::init ();
	}	
	
	/**
	 * Sets correct values for guest_type & default_type fields 
	 *
	 */
	protected function _beforeModify() {
		if ($this->_request->getParam ( 'is_guest' )) {
			$this->_model->resetGuestGroup ();
		} else {
			$this->_request->setParam ( 'is_guest', 0 );
		}
		
		if ($this->_request->getParam ( 'is_default' )) {
			$this->_model->resetDefaultGroup ();
		} else {
			$this->_request->setParam ( 'is_default', 0 );
		}
	}
	
	/**
	 * Clear ACL cache after group deletion
	 *
	 */
	protected function _afterDelete(){
		Helpers_Usermanagement_Cache::cleanAclCacheForGroup($this->_current_entry['user_group_id']);
	}
}